<template>
		<div class="container" v-title data-title='个人中心'>
		<Header title="个人中心"></Header>
		<Person_top></Person_top>
		<div class="total-commission">
			<h3>
				<a href="javascript:;" v-on:click="turnPresimes">
					佣金总额数<small>（元）</small><br/><strong>{{customer.totalAmount.toFixed(2)}}</strong>
				</a>
			</h3>	
			<div class="commission-bottom">
				<a href="javascript:;" class="col-sm-6" v-on:click="turnPresimes">
					已结佣<small>（元）</small><br/><strong>{{customer.hasbalance.toFixed(2)}}</strong>
				</a>
				<a href="javascript:;" class="col-sm-6" v-on:click="turnPresimes">
					待结佣<small>（元）</small><br/><strong>{{customer.hasnobalance.toFixed(2)}}</strong>
				</a>
			</div>
		</div>
		<!--
        	作者：353895897@qq.com
        	时间：2017-03-17
        	描述：合作协议去掉,需求原型上无此内容
        -->
        <!--
		<div class="line bor-b"></div>
		<ul class="ul-list-view list-view-icon-right">
			<li class="ul-list-view-cell pT14 pB14">
				<a href="javascript:;" class="list-navigate-right">
					<i class="fa fa-file-text-o my-icon"></i>
					合作协议
				</a>
			</li>
		</ul>
		-->
		<div class="line bor-b"></div>
		<ul class="ul-list-view list-view-icon-right">
			<li class="ul-list-view-cell pT14 pB14">
				<a href="javascript:;" class="list-navigate-right" v-on:click="changePwd">
					<i class="fa fa-unlock-alt my-icon fa-fw" aria-hidden="true"></i>
					修改密码
				</a>
			</li>
		</ul>
		<ul class="ul-list-view list-view-icon-right" v-if="!isShow">
			<li class="ul-list-view-cell pT14 pB14">
				<a href="javascript:;" class="list-navigate-right" v-on:click="bindCompany">
					<i class="fa fa-handshake-o my-icon fa-fw" aria-hidden="true"></i>
					绑定公司
				</a>
			</li>
		</ul>
		<ul class="ul-list-view list-view-icon-right" v-if="isShow">
			<li class="ul-list-view-cell pT14 pB14">
				<a href="javascript:;" >
					<i class="fa fa-square-o my-icon fa-fw"></i>
					<!--公司代码<input v-model="company.companyCode" style="float: right;text-align: right;" readonly />-->
					公司代码<span style="float:right;">{{company.companyCode}}</span>
				</a>
			</li>
		</ul>
		<ul class="ul-list-view list-view-icon-right" v-if="isShow">
			<li class="ul-list-view-cell pT14 pB14">
				<a href="javascript:;">
					<i class="fa fa-camera-retro my-icon fa-fw" aria-hidden="true"></i>
					<!--所属公司<input v-model="company.companyName" style="float: right;text-align: right;" readonly />-->
					所属公司<span style="float:right;">{{company.companyName}}</span>
				</a>
			</li>
		</ul>
		<ul class="ul-list-view  mT120 bor-t" style="margin-top: 40px;">
			<li class="ul-list-view-cell pT14 pB14 trC" v-on:click="quit">
				<a href="javascript:;">
					退出登录
				</a>
			</li>
		</ul>
	</div>
</template>
<script>
import Person_top from '../../components/common/person_top.vue'
	export default{
		data(){
			return {
				customer:{
					totalAmount:0,
					hasbalance:0,
					hasnobalance:0
				},
				company:{
					companyCode:"",
					companyName:"",
					status:""
				},
				isShow:false
			}
		},components: {
			Person_top
		},
		mounted: function() {
			//初始化数据
			this.initCustomerInfo();
			this.loadCompany();
            $("#goble_menu_div").show();
		},
		methods:{
			bindCompany:function(){
				this.$router.push({name:'BindCompany'});
			},
			initCustomerInfo:function(){
				var _self = this;
				var body = {};
				body.params = {
					isturn:false
				}
				var url = this.utilHelper.apiUrl+'/api/getCustomerPremises';
				_self.$http.post(url,body).then((response)=>{
					var body = response.body;
					if(body.result==1){
							_self.customer.totalAmount = body.resData.totalAmount;
							_self.customer.hasbalance = body.resData.hasbalance;
							_self.customer.hasnobalance = body.resData.hasnobalance;
					}else{
						layer.msg("数据获取失败");
					}
				});
			},
			changePwd:function(){
				this.$router.push({
					path: '/changepwd'
				})
			},
			quit:function(){
				var _self = this;
				var body = {};
				var params = {
                    userId: window.sessionStorage.getItem(_self.utilHelper.appAgency+"_userId"),
                    loginType:'3'
				}
				body.params = params;
				var url = _self.utilHelper.apiUrl + "/api/loginOut";
				_self.$http.post(url, body).then((response) => {
					var data = response.body;
					var result = data.result;
					var resData = data.resData;
					window.sessionStorage.setItem(_self.utilHelper.appAgency+"_isLogin",false);
//                    window.sessionStorage.removeItem(this.utilHelper.appAgency+"_userId");
                    window.sessionStorage.removeItem(_self.utilHelper.appAgency+"_userName");
                    window.sessionStorage.removeItem(_self.utilHelper.appAgency+"_userRole");
                    window.sessionStorage.removeItem(_self.utilHelper.appAgency+"_accountType");
					window.sessionStorage.removeItem(_self.utilHelper.appAgency+"_phone");
					
					_self.$router.replace({
						path: '/login'
					})
				}, (response) => {});
			},
			turnPresimes:function(){
				var _self = this;
				_self.$router.replace({
					path: '/commission'
				})
			},
			loadCompany:function(){
				//加载公司信息
				var _self = this;
				var body =  {};
				body.params = {};
				var url = this.utilHelper.apiUrl+'/api/getCompanyByUserId';
				_self.$http.post(url,body).then((response)=>{
					var body = response.body
					if(body.result==1){
						_self.company = body.resData.company;
						if(_self.company.companyCode){
							_self.isShow = true;
							_self.getPartnerInfo();
						}
					}
				})
			},
			 //实时获取用户信息
            getPartnerInfo(){
		        var _self = this;
		        var body = {};
		        body.params = {}
		        var url = this.utilHelper.apiUrl+'/api/getUserById';
		          _self.$http.post(url, body).then((response) => {
		              var data = response.body;
		              var result = data.result;
		              if (result == "1") {
		                  window.sessionStorage.setItem(_self.utilHelper.appAgency+"_userId", data.resData.id);
		                  window.sessionStorage.setItem(_self.utilHelper.appAgency+"_userName", data.resData.accountName);
		                  window.sessionStorage.setItem(_self.utilHelper.appAgency+"_phone", data.resData.phone);
		                  window.sessionStorage.setItem(_self.utilHelper.appAgency+"_userRole", data.resData.userRoleId);
		              }
		          });
		      }
		}
	}
	
</script>